package com.wenhai.spring.generic;

import org.springframework.core.GenericTypeResolver;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
 * {@link GenericTypeResolver} 示例
 *
 * @author wenhai
 * @date   2021/4/9
 */
public class GenericTypeResolverDemo {
    public static void main(String[] args) throws NoSuchMethodException {
        Method method = GenericTypeResolverDemo.class.getDeclaredMethod("getString");
        Method genericReturn = GenericTypeResolverDemo.class.getDeclaredMethod("genericReturn");
        Class<?> returnType = GenericTypeResolver.resolveReturnType(method, GenericTypeResolverDemo.class);
        Class<?> returnTypeArgument = GenericTypeResolver.resolveReturnTypeArgument(method, GenericTypeResolverDemo.class);
        Class<?> genericReturnC = GenericTypeResolver.resolveReturnTypeArgument(genericReturn, List.class);
        Map<TypeVariable, Type> typeVariableMap = GenericTypeResolver.getTypeVariableMap(Properties.class);
        System.out.println(returnType.getName());
        System.out.println(returnTypeArgument);
        System.out.println(genericReturnC);
        System.out.println(typeVariableMap);

    }

    public static String getString() {
        return null;
    }

    public static List<String> genericReturn() {
        return null;
    }
}
